package com.tree.backend.controller;

import com.tree.backend.common.Result;
import com.tree.backend.entity.dto.LoginDTO;
import com.tree.backend.service.IUserService;
import com.tree.backend.entity.vo.LoginVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 认证控制器
 */
@RestController
@RequiredArgsConstructor
public class AuthController {

    private final IUserService userService;

    /**
     * 用户登录接口
     * @param loginDTO 登录请求参数
     * @return 登录结果
     */
    @PostMapping("/login")
    public Result<LoginVO> login(@RequestBody LoginDTO loginDTO) {
        LoginVO loginVO = userService.login(loginDTO.getUsername(), loginDTO.getPassword());
        return Result.success(loginVO);
    }

    /**
     * 用户登出接口
     * @return 登出结果
     */
    @PostMapping("/logout")
    public Result<String> logout() {
        userService.logout();
        return Result.success("登出成功");
    }
}